package com.hdfs.api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.IOException;


//读hdfs文件
public class HDFSReadDemo {

    public static void main(String[] args) throws IOException {

        //1.创建配置类并设置配置
        Configuration config = new Configuration();
        //配置hdfs
        config.set("fs.defaultFS","hdfs://10.90.100.101:9820");
        //2.获取文件系统的对象
        FileSystem fs = FileSystem.get(config);
        //3.设置读取hdfs目标文件的路径
        Path filePath = new Path("/ifconfig.txt");
        //4.获取读取目标文件的输入流
        FSDataInputStream in = fs.open(filePath);
        //5.使用IO工具将输出流输出到终端
        IOUtils.copyBytes(in,System.out,config);
        //6.关流
         in.close();


    }

}
